#coding:utf-8

from django.db import models

# Create your models here.


class BusinessGroup(models.Model):
    chinese_name = models.CharField(max_length=128, unique=True, db_index=True, verbose_name=u'业务组中文名称')
    english_name = models.CharField(max_length=128, unique=True, db_index=True, verbose_name=u'业务组英文名称')
    desc = models.CharField(max_length=256, null=True, verbose_name=u'业务组描述')
    rank = models.IntegerField(default=0, verbose_name=u'排序')

    class Meta:
        verbose_name = '业务组名称'
        verbose_name_plural = verbose_name
        ordering = ['rank']
    def __unicode__(self):
        return self.english_name

class TeamUser(models.Model):
    chinese_name = models.CharField(max_length=128, unique=True, db_index=True, null=False, verbose_name=u'中文名')
    english_name = models.CharField(max_length=128, unique=True, db_index=True, null=False, verbose_name=u'英文名')
    email = models.EmailField(max_length=128, unique=True, db_index=True, null=False, verbose_name=u'邮箱地址')
    phone_num = models.BigIntegerField(max_length=64, blank=True, null=False, verbose_name=u'手机号码')
    business_group = models.ManyToManyField('BusinessGroup', blank=True, verbose_name=u'关联组')
    is_leader = models.BooleanField(default=False, verbose_name=u'组长')
    is_disable = models.BooleanField(default=False, verbose_name=u'禁用')
    rank = models.IntegerField(default=0, verbose_name=u'排序')

    class Meta:
        verbose_name = u'组成员'
        verbose_name_plural = verbose_name
        ordering = ['rank']
    def __unicode__(self):
        return self.english_name


class PackageName(models.Model):
    name = models.CharField(max_length=128, unique=True, db_index=True, verbose_name=u'应用名')
    business_group = models.ManyToManyField('BusinessGroup', blank=True, verbose_name=u'关联组')
    team_user = models.ManyToManyField('TeamUser', blank=True, verbose_name=u'关联用户')
    rank = models.IntegerField(default=0, verbose_name=u'排序')
    desc = models.CharField(max_length=256, verbose_name=u'应用描述')

    class Meta:
        verbose_name = u'应用名'
        verbose_name_plural = verbose_name
        ordering = ['rank']
    def __unicode__(self):
        return self.name